package com.ruoyi.file.service.impl;



import com.ruoyi.file.mapper.FileMapper;

import com.ruoyi.file.pojo.FilePojo;
import com.ruoyi.file.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;
import java.util.List;

/**
 * @author jpj
 * date 2022/4/8 9:55
 */
@Service
public class FileServiceImpl implements FileService {

    String filepath = "H:\\file";
    BufferedInputStream  bufferedInputStream;
    BufferedOutputStream bufferedOutputStream;
    byte[] bytes=new byte[1024*100];
    @Autowired
    FileMapper fileDao;
    @Override
    public List<FilePojo> findList(FilePojo file) {
        return fileDao.findList(file);
    }

    @Override
    public int insert(MultipartFile file) {
        FilePojo filePojo=new FilePojo();
        filePojo.setFileName(file.getOriginalFilename());
        try {
            file.transferTo(new File(filepath+"\\"+file.getOriginalFilename()));
        } catch (IOException e) {
            e.printStackTrace();
        }
        filePojo.setDownload(filepath+"\\"+file.getOriginalFilename());
        int i=fileDao.insert(filePojo);
        return i ;
    }

    @Override
    public int update(FilePojo file) {
        return 0;
    }

    @Override
    public int delete(String id) {
        return 0;
    }

    @Override
    public FilePojo get(String id) {
        return null;
    }
    public FilePojo getFile(Integer id){
        return fileDao.getFile(id);
    }
}
